package com.wzh.bigfileupload.controller;

import com.wzh.bigfileupload.form.FileForm;
import com.wzh.bigfileupload.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Map;


@RestController
@RequestMapping("/file")
public class UploadFileController {

    @Autowired
    UploadFileService uploadFileService;




    @PostMapping("/upload")
    public Map<String, Object> upload(@Valid FileForm form,
                                      @RequestParam(value = "data", required = false)MultipartFile multipartFile) {
        Map<String, Object> map = null;

        try {
            map = uploadFileService.realUpload(form, multipartFile);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

}
